package com.example.administrator.yunniuusedcar.activity;


import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import com.example.administrator.common.base.BaseActivity;
import com.example.administrator.yunniuusedcar.fragment.Tool_fragment.FullPayment;
import com.example.administrator.yunniuusedcar.fragment.Tool_fragment.LoanDaiKuan;
import com.example.administrator.yunniuusedcar.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

//<!-- 购车计算-->
public class BuyCarCountActivity extends BaseActivity {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_Remove)
    TextView tvRemove;
    @BindView(R.id.radiobutton_FullPay)
    RadioButton radiobuttonFullPay;
    @BindView(R.id.radiobuttonLoanPay)
    RadioButton radiobuttonLoanPay;
    @BindView(R.id.radioGroups)
    RadioGroup radioGroupss;
    @BindView(R.id.fl_buyCar_car)
    FrameLayout flBuyCarCar;

     int CurrentIndex ;
    private Fragment[] frg;

    @Override
    public int getLayoutRes() {
        return R.layout.activity_buy_car_count;
    }

    @Override
    public void initView() {

        ButterKnife.bind(this);

        // mView = View.inflate(this, R.layout.activity_details_car, null);
        initToolBar();
        initEvent();
    }

    //创建集合
    private void initEvent() {
        frg = new Fragment[]{
                new FullPayment() , new LoanDaiKuan(),
          };
        //开启事务
        FragmentTransaction fts = getSupportFragmentManager().beginTransaction();
        fts.add(R.id.fl_buyCar_car, frg[0]).commit();    // 设置为默认界面 //fl_ZGhao_car

        // 设置单选组 的监听事件 切换fragment
        radioGroupss.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
                switch (checkedId) {
                    case R.id.radiobutton_FullPay:
                        setIndexSelecteds(0);
                        break;
                    case R.id.radiobuttonLoanPay:
                        setIndexSelecteds(1);
                        break;

                }
            }
        });
    }

    private void setIndexSelecteds(int index) {   // 设置fragment 界面
        if (CurrentIndex == index) {
            return;
        }
        // 开启事务
        FragmentTransaction ftt = getSupportFragmentManager().beginTransaction();
        //y隐藏事务
        ftt.hide(frg[CurrentIndex]);

        // 判断当前的fragment是否已添加
        if (!frg[index].isAdded()) {
            ftt.add(R.id.fl_buyCar_car, frg[index]).show(frg[index]);  // 用事务区添加，省内存

        } else {
            ftt.show(frg[index]);
        }
    }


    private void initToolBar() {

    }

    private void initGoShoopingCar() {   // 购物车

    }

    private void initSearch() {     //搜索

    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {

    }

    @OnClick({R.id.iv_back, R.id.tv_Remove})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_Remove:
                break;
        }
    }



}
